package com.attilax.media;

import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.MultimediaInfo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;
import m.coll.hashmapAti;

import com.attilax.core;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.text.strUtil;

/**
 * JAVE gives you an abstract class called it.sauronsoftware.jave.FFMPEGLocator. Extend it. All you have to do is to define the following method:

public java.lang.String getFFMPEGExecutablePath()

This method should return a file system based path to your custom ffmpeg executable.
 * @author Administrator
 *
 */
public class MediaInfo {

	public static void main(String[] args) {
		//z:\动作类\飓风营救3\飓风营救3.mkv
		String s="Z:\\动作类\\飓风营救3\\飓风营救3.mkv";
		System.out.println("--");
		System.out.println("aa");
		System.out.println(getMediainfo(s));
//		 String f = "Z:\\喜剧类\\宿醉 豆瓣评分7.7/宿醉.mkv";
//		 
//	 	f="z:\\悬疑类\\狙击电话亭/狙击电话亭.mkv";
//	 	f=pathx.fixSlash(f);
//	 	System.out.println(f);
//		System.out.println("---aa");
//	//	core.newThread(futTask, threadName)
//		
//		final	String f3=f;
//	core.newThread(new Runnable() {
//		
//		@Override
//		public void run() {
//			System.out.println(core.toJsonStrO88(getMediainfo(f3)));
//			
//		}
//	}, "threadName");
//		
		System.out.println("--f");
		//duration
	}

	
	/**
	 * duration unit secs
	 * @param f
	 * @return
	 */
	public static Map getMediainfo(String f) {
		File fil = new File(f);
		Encoder encoder = new Encoder();
		MultimediaInfo m = null;
		try {
			m = encoder.getInfo(fil);
		} catch (Throwable e) {

			filex.saveLog(e, "c:\\e");
		}
		long ls = m.getDuration();// millSecs
		ls = ls / 1000;
		Map mp = new HashMap();
		mp.put("Duration", ls);
		mp.put("duration", ls);
		String jsonStrO88 = core.toJsonStrO88(m);
		System.out.println(jsonStrO88);
		
		//JSONObject.fromObject(jsonStrO88);
		return mp;
		// return null;
	}

}
